package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.Round;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 心灵鸡汤<br/>
 * 帮助员工树立信心，<br/>
 * 为所有员工增加{0=5#0}层状态，<br/>
 * 员工每次行动消耗一层状态恢复自身当前生命{1=20#0}%的生命值，<br/>
 * 若此状态被强制驱散，则每层状态恢复员工自身最大生命值{2=20#0}%
 * @author yang.li
 *
 */
public class COMBAT_SKILL_100007 extends CombatSkill {

	public COMBAT_SKILL_100007(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		List<CombatUnit> units = action.unit.getTeam().all();
		for (int i = 0; i < units.size(); i++) {
			CombatUnit unit = units.get(i);
			if (!unit.isDied()) {
				action.addBuff(new BUFF(skill, unit));
			}
		}
	}
	
	static class BUFF extends CombatBuff {
		int layers;
		float rate1, rate2;
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner);
			active = true;
			layers = (int) skill.getParameter(0);
			rate1 = skill.getParameter(1) / GameStaticConfig.percentBase;
			rate2 = skill.getParameter(2) / GameStaticConfig.percentBase;
		}
		@Override
		public void preAction(Action action) {
			ActionEffect effect = action.addTarget(owner);
			effect.effect(CombatAttributeType.HP, (int) (rate1 * owner.getHp()));
			if (--layers <= 0) {
				uneffect();
			}
		}
		@Override
		public void roundEnd(Round round) {
			if (state == STATE_REMOVED) {
				round.addBuff(this);
			}
		}
	}

}
